package com.drug.mingkang.controller;

import com.alibaba.fastjson.JSONObject;
import com.drug.mingkang.model.HqPdetail;
import com.drug.mingkang.service.HqDrugtypeService;
import com.drug.mingkang.service.HqPdetailService;
import com.drug.mingkang.utils.ProductTypeParent;
import com.drug.mingkang.utils.ResponseMessage;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 总公司计划明细(HqPdetail)表控制层
 *
 * @author xqj
 * @since 2020-08-11 12:00:13
 */
@RestController
@RequestMapping("hqPdetail")
public class HqPdetailController {
    /**
     * 服务对象
     */
    @Resource
    private HqPdetailService hqPdetailService;

    @Resource
    private HqDrugtypeService hqDrugtypeService;

    /**
     * 通过生产计划id查询单条数据
     *
     * @param planId 计划生产主键
     * @return 单条数据
     */
    @ApiOperation(value = "通过生产计划id查询单条数据",notes = "传入计划单ID PlanId",httpMethod = "GET",response = ResponseMessage.class)
    @GetMapping("selectOne")
    public List<HqPdetail> selectOne(String planId) {
        return this.hqPdetailService.queryById(planId);
    }


    /**
     * 批量增加计划明细
     * @param wl
     * @return
     */
    @ApiOperation(value = "批量增加计划明细",notes = "传入一个生产计划对象数组的JSON字符串",httpMethod = "POST",response = ResponseMessage.class)
    @PostMapping("insert")
    public ResponseMessage insert(String wl){

        List<HqPdetail> list = JSONObject.parseArray(wl, HqPdetail.class);


        ResponseMessage responseMessage = hqPdetailService.insertAll(list);

        return responseMessage;
    }


    /**
     * 查询药品的树状数据
     * @return
     */
    @ApiOperation(value = "查询药品的树状数据",httpMethod = "POST",response = Map.class)
    @PostMapping("getTypeTree")
    public Map<String,Object> getTree(){
        List<ProductTypeParent> list = hqDrugtypeService.getTree();
        Map<String,Object> map = new HashMap<>();
        map.put("data",list);
        map.put("code",0);
        return map;
    }



}